﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace IrisGenerator.Common.Tools
{
    internal class XmlLinq
    {
        internal static XElement LoadSingleDescendantNode(XElement parent, string nodeName)
        {
            var dbQuery = from node in parent.Descendants(nodeName)
                          select node;
            if (dbQuery.Count() > 1)
                throw new ArgumentException("The config section for " + nodeName +
                    " appears more than once for " + parent.Name.LocalName);

            if (dbQuery.Count().Equals(1))
                return dbQuery.ElementAt(0);

            return null;
        }

        
    }
}
